package com.boang.web;

import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

/*
  @author: 13813
  @date: 2024/7/11 14:31
*/
@WebServlet("/h01")
public class ServletDemo01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("ServletDemo01--doGet");
//        RequestDispatcher rd = req.getRequestDispatcher("/h02");
//        rd.forward(req, resp);//转发

        resp.getWriter().write("ServletDemo01--doGet");
//        resp.sendRedirect("https://www.baidu.com");//重定向
        //
        resp.sendRedirect(req.getContextPath() + "/h02");//重定向
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("resp = " + resp);
    }
}
